package screens;

import gameobjects.Button;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import resources.Music;
import resources.Sprite;
import tools.GameApplet;
import tools.Statistics;
import abstracts.Level;
import abstracts.Screen;

/** */
public class StatisticsScreen extends Screen {
    /** Main Menu. */
    private Button menuButton;

    /**
     * @param gameApplet - the {@link GameApplet} which this screen is
     *            to be displayed in.
     */
    public StatisticsScreen(final GameApplet gameApplet) {
        super(gameApplet);
    }

    @Override
    public final void begin() {
        Music.set(Music.MAIN_MENU);

        menuButton = new Button(Sprite.MAIN_MENU_BUTTON, getWidth() / 2, 400,
                new Runnable() {
                    @Override
                    public final void run() {
                        getApplet().setScreen(new MenuScreen(getApplet()));
                    }
                });
        getApplet().getCanvas().addMouseListener(menuButton);
        getApplet().getCanvas().addMouseMotionListener(menuButton);
    }

    @Override
    public final void draw(final Graphics g) {
        g.setColor(Color.BLACK);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(Color.WHITE);

        g.setFont(new Font("Georgia", Font.BOLD, 48));
        String text = "Statistics";
        int w = g.getFontMetrics().stringWidth(text);
        g.drawString(text, (getWidth() - w) / 2, 64);

        g.setFont(new Font("Georgia", Font.BOLD, 12));
        text = "Treasure: " + Statistics.treasure;
        w = g.getFontMetrics().stringWidth(text);
        g.drawString(text, (getWidth() - w) / 2, 128);

        menuButton.draw(g);
    }

    @Override
    public final void end() {
        getApplet().getCanvas().removeMouseListener(menuButton);
        getApplet().getCanvas().removeMouseMotionListener(menuButton);
        menuButton = null;
    }

    @Override
    public final int getHeight() {
        return Level.HEIGHT;
    }

    @Override
    public final int getWidth() {
        return Level.WIDTH;
    }
}
